#include "ErrorModel.h"

ErrorModel::ErrorModel(const QList<Plugins::ErrorItem> & list, QObject * parent):
    QAbstractTableModel(parent),
    _list(list)
{

}

int ErrorModel::rowCount(const QModelIndex &/*parent*/) const
{
    return _list.length();
}

int ErrorModel::columnCount(const QModelIndex &/*parent*/) const
{
    return 3;
}

QVariant ErrorModel::data(const QModelIndex &index, int role) const
{
    Plugins::ErrorItem node = _list.at(index.row());
    if (role == Qt::DisplayRole){
        switch(index.column()){
        case 0:
            return node.type;
        case 1:
            return node.message;
        case 2:
            return node.lineNo;
        }
    }
    if (role == Qt::EditRole)
        return node.lineNo;
    return QVariant();
}
QVariant ErrorModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole){
        switch(section){
        case 0:
            return tr("Code");
        case 1:
            return tr("Message");
        case 2:
            return tr("Line");
        }
    }
    return QVariant();
}

